# -*- coding: utf-8 -*-
# @Time : 2021/9/6 18:22
# @Author : 唐宁
# @Site : 
# @File : OrderDaoProvider.py
# @Software: PyCharm
from core.order.dto.OrderDTO import OrderDTO


def getOrderList(dto: OrderDTO):
    """
    获取订单列表
    :param dto: 动态查询数据
    :return: sql
    """
    sql = f"SELECT a.*," \
          f"b.account," \
          f"b.status as 'account_status' " \
          f"FROM order_info a left join user_info b on " \
          f"a.user_id = b.user_id " \
          f"WHERE 1 = 1 "
    # 订单编号(字符串类型，要添加 '')（实体中的值）
    if dto.order_no is not None:
        sql += f" AND INSTR( a.order_no , '{dto.order_no}' ) > 0 "
    # 用户ID （实体中的值）
    if dto.user_id is not None:
        sql += f" AND a.user_id = {dto.user_id} "
    # 用户账户（DTO的值）
    if dto.account is not None:
        sql += f" AND INSTR( b.account , '{dto.account}') > 0 "
    sql += " ORDER BY id  "
    return sql
